<template>
  <div>
    <!--头部-->
    <div class="front-header">
      <div class="front-header-left">
        <img src="@/assets/img/logo.png" alt="">
        <div class="title">大学生成长成才监测平台</div>
      </div>
      <div class="front-header-center">
        <div class="front-header-nav">
          <el-menu :default-active="$route.path" mode="horizontal" router>
						<el-menu-item index="/student/home">首页</el-menu-item>
						<el-menu-item index="/student/Contest">竞赛与课程</el-menu-item>
						<el-menu-item index="/student/learningHabit">学习习惯</el-menu-item>
						<el-menu-item index="/student/PsyList">心理健康</el-menu-item>
<!--            <el-menu-item index="/student/message">消息</el-menu-item>-->
            <el-menu-item index="/student/person">个人中心</el-menu-item>
          </el-menu>
        </div>
      </div>
      <div class="front-header-right">
        <el-dropdown>
          <div class="front-header-dropdown">
<!--            <img :src="user.avatar" alt="">-->
            <div style="margin-left: 10px; color: white">
              <span>{{ user.name }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
            </div>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>
                <div style="text-decoration: none" @click="navTo('/student/person')">个人中心</div>
              </el-dropdown-item>

              <el-dropdown-item>
                <div style="text-decoration: none" @click="logout">退出</div>
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <!--主体-->
    <div class="main-body">
      <router-view ref="child" @update:user="updateUser" />
    </div>
  </div>

</template>

<script>

export default {
  name: "Student",

  data () {
    return {
      user: JSON.parse(localStorage.getItem("honey-user") || '{}'),
    }
  },


  methods: {
    navTo(path) {
      this.$router.push(path);
    },
    updateUser() {
      this.user = JSON.parse(localStorage.getItem('honey-user') || '{}')   // 重新获取下用户的最新信息
    },
    // 退出登录
    logout() {
      localStorage.removeItem("honey-user");
      this.$router.push("/");
    },
    navTo(url) {
      location.href = url
    }
  }
}
</script>

<style scoped>
@import "@/assets/css/student.css";

</style>